﻿//AcademicPlanner - course registration planning web app.
//Copyright (C) 2009  Boubacar Diallo

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


using System;
using System.Web.Mvc;
using AcademicPlanner.Presentation.Views.Shared;
using AcademicPlanner.Domain.Models;
using AcademicPlanner.Framework.Helpers;

namespace AcademicPlanner.Presentation.Views.MyAccount
{
	/// <summary>
	/// MyAccountSettingsViewModel represents a model for a
	/// <c>Settings</c> view.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public class MyAccountSettingsViewModel
	{
		/// <summary>
		/// Gets or sets the <c>Person</c> a <c>Settings</c> view
		/// is concerned with.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public Person Person { get; set; }
	}


	/// <summary>
	/// Settings represents the web page to edit a user's personal
	/// information and account settings. It embeds a <c>PersonForm</c>
	/// and a <c>AccountForm</c>.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public partial class Settings : View<MyAccountSettingsViewModel>
	{
		/// <summary>
		/// Gets or sets the model for the <c>PersonForm</c> embedded in this view.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public PersonFormModel SavePersonModel { get; set; }

		/// <summary>
		/// Gets or sets the model for the <c>AccountForm</c> embedded in this view.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public AccountFormModel SaveAccountModel { get; set; }


		/// <summary>
		/// Handles the page load event for this Settings view.
		/// This methods intializes the page title and heading
		/// as well as the models for the embedded forms.
		/// </summary>
		/// <param name="sender">The sender of the event.</param>
		/// <param name="e">The details about the event.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		protected void Page_Load(object sender, EventArgs e)
		{
			pageHeading = Tr("My Account Settings");
			Title = string.Format(Tr(titleFormat), pageHeading);
			pageTip = App_LocalResources.PageTips.MyAccountSettings;

			SavePersonModel = new PersonFormModel();
			SavePersonModel.Scenario = PersonFormScenario.EDIT;
			SavePersonModel.Person = Model.Person;

			SaveAccountModel = new AccountFormModel();
			SaveAccountModel.Scenario = AccountFormScenario.EDIT;
			SaveAccountModel.Account = Model.Person.Accounts.WithUserName(SessionHelper.GetUserName());
		}
	}
}
